﻿using System.Windows;
using System.Windows.Controls;
using Prism.Regions;

namespace Coniometer.Pages
{
    public partial class DataPage : UserControl
    {
        private readonly IRegionManager _regionManager;

        public DataPage(IRegionManager regionManager)
        {
            InitializeComponent();
            _regionManager = regionManager;
            Loaded += DataPage_Loaded;
            DataPageTabControl.SelectionChanged += TabControl_SelectionChanged;
        }

        private void DataPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (DataPageTabControl.Items.Count > 0 && DataPageTabControl.SelectedIndex == -1)
            {
                DataPageTabControl.SelectedIndex = 0;
                NavigateToSelectedTab();
            }
        }

        private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            NavigateToSelectedTab();
        }

        private void NavigateToSelectedTab()
        {
            if (!(DataPageTabControl.SelectedItem is TabItem selectedTab)) return;
            var region = _regionManager.Regions["DataContentRegion"];
            switch (selectedTab.Header.ToString())
            {
                case "样本数据":
                    region.RequestNavigate("SimpleDataPage");
                    //通知页面刷新数据
                    break;
                case "SOP数据":
                    region.RequestNavigate("SopDataPage");
                    //通知页面刷新数据
                    break;
                case "审计追踪":
                    region.RequestNavigate("AuditTrailPage");
                    //通知页面刷新数据
                    break;
            }
        }
    }
}